package com.star.common.kit.language.chain;

import com.star.common.kit.contract.enums.language.detail.EnglishLanguageEnum;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 语言责任链工厂
 *
 * @author zhouhengzhe
 * @version 1.0
 * @date 2023/9/7 16:28
 */
@Component
@RequiredArgsConstructor
public class LanguageChainFilterFactory {

    private final List<LanguageChainFilter> languageChainFilters;

    public String handle(String languageCode){
        for (LanguageChainFilter languageChainFilter : languageChainFilters) {
            String realLanguage = languageChainFilter.getLanguage(languageCode);
            if (StringUtils.isNotBlank(realLanguage)){
                return realLanguage;
            }
        }
        //防止特殊情况没有语言匹配
        return  EnglishLanguageEnum.EN.getCode();
    }

}
